package cn.yunhe.controller;

import cn.yunhe.model.Dept;
import cn.yunhe.model.Page;
import cn.yunhe.service.IDeptService;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
public class DeptController extends ActionSupport implements ModelDriven<Object>{
    @Resource(name="deptService")
    private IDeptService deptService;
    private Dept dept;
    private Page page;
    private int pageSize;
    private int pageNum;

    public String queryLikeDept(){
        System.out.println("执行了queryLikeDept");
        Map<String ,Object> cond = new HashMap<String,Object>();
        cond.put("pageSize",pageSize);
        cond.put("pageNum",pageNum);
        cond.put("dept",dept);
        page = deptService.queryLikeDept(cond);
        return SUCCESS;
    }

    public String addDept(){
        deptService.addDept(dept);
        return SUCCESS;
    }

    public String delDept(){
        deptService.delDept(dept);
        return SUCCESS;
    }

    public String findDept(){

        dept = deptService.findDept(dept);
        Map map = (Map) ActionContext.getContext().get("request");
        System.out.println(dept.toString());
        map.put("dept",dept);
        return SUCCESS;
    }

    public String editDept(){
        System.out.println(dept.toString());
        deptService.editDept(dept);
        return SUCCESS;
    }


    public IDeptService getDeptService() {
        return deptService;
    }

    public void setDeptService(IDeptService deptService) {
        this.deptService = deptService;
    }

    public Dept getDept() {
        return dept;
    }

    public void setDept(Dept dept) {
        this.dept = dept;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    @Override
    public Object getModel() {
        if(dept == null){
            dept = new Dept();
        }
        return dept;
    }
}
